import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 87111
 * Date: 2025-11-08
 * Time: 14:24
 */
public class Demo2 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        //安全的
        List<String> list2 = Collections.synchronizedList(list);

        CopyOnWriteArrayList<Character> list3 = new CopyOnWriteArrayList<>();

        list3.add('A');
        list3.add('B');

        //迭代器：基于列表的快照进行遍历
        Iterator<Character> iterator = list3.iterator();
        list3.add('C');

        while(iterator.hasNext()) {
            System.out.print(iterator.next() + " ");
        }
        System.out.println();
        System.out.println("更新后的数据：" );
        for(char c : list3) {
            System.out.print(c + " ");
        }
    }
}
